package cn.t.service.user;

import cn.t.core.mode.YesNoEnum;
import cn.t.core.service.ServiceImpl;
import cn.t.core.enums.base.BaseStatusEnum;
import cn.t.model.user.RoleDeviceDO;
import cn.t.repository.user.RoleDeviceRepository;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;


/**
 * @author l
 */
@Slf4j
@Service
@AllArgsConstructor
public class RoleDeviceService extends ServiceImpl<RoleDeviceDO, RoleDeviceRepository> {

    public List<RoleDeviceDO> findByRoleId(Set<Long> roleIdList) {

        if (roleIdList == null) {
            return null;
        }
        List<RoleDeviceDO> ret = new ArrayList<>();

        for (Long roleId : roleIdList) {
            List<RoleDeviceDO> roleDeviceList = findByRoleId(roleId);
            if (roleDeviceList == null || roleDeviceList.isEmpty()) {
                continue;
            }
            ret.addAll(roleDeviceList);
        }

        return ret;
    }

    public List<RoleDeviceDO> findByRoleId(Long roleId) {
        RoleDeviceDO template = new RoleDeviceDO();
        template.setRoleId(roleId);
        template.setStatus(String.valueOf(BaseStatusEnum.AVAILABLE.getCode()));
        template.setIsDeleted(YesNoEnum.FALSE);

        return repository.findByModel(template, 0, 10000, "id", "asc");
    }




}
